from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator
from twisted.protocols import amp
from tweetographerServer import GetTweet

class tweetObject:
    def __init__(self):
        #boolean variables for flagging confidence criteria
        self.hasDayName = False
        self.hasAddress = False
        self.hasDate = False
        self.hasTime = False
        self.hasDay = False
        self.hasAct = False
        self.hasMonth = False
        self.hasSpecial = False
        self.hasFoursq = False
        #tweet information, i.e. username, long/lat coordinates, tweet text
        self.longitude = None
        self.latitude = None
        self.userName = None
        self.city = 0
        self.text = ""
        self.score = 0
        self.eventDate = None
        #list comprehension of boolean variables for confidence criteria defined above
        self.regexMatches = [self.hasAddress,self.hasDayName,self.hasAct,self.hasMonth,self.hasTime,self.hasSpecial,self.hasFoursq,self.hasDay,self.hasDate]

    def updateMatches(self):#have to refresh the values for booleans when they are changed because the array is pass-by-value
        self.regexMatches = [self.hasAddress,self.hasDayName,self.hasAct,self.hasMonth,self.hasTime,self.hasSpecial,self.hasFoursq,self.hasDay,self.hasDate]

def retrieve():
    d1 = ClientCreator(reactor, amp.AMP).connectTCP('127.0.0.1', 1234).addCallback(lambda p: p.callRemote(GetTweet)).addCallback(lambda result: result['tweet'])
    def done(result):
        print 'Done with math:', result
    defer.DeferredList([d1]).addCallback(done)

if __name__ == '__main__':  
	while 1:
	  	retrieve()
		reactor.callLater(2, reactor.stop)
		reactor.run()  
